Skip to content

Fix get_dummy_wan_inputs for two-expert Wan2.2-I2V-A14B pipeline#427

Open
ThomasNing wants to merge 2 commits into
AI-Hypercomputer:mainfrom
ThomasNing:fix/wan22-i2v-2.2-quant-dummy-inputs
Open

Fix get_dummy_wan_inputs for two-expert Wan2.2-I2V-A14B pipeline#427
ThomasNing wants to merge 2 commits into
AI-Hypercomputer:mainfrom
ThomasNing:fix/wan22-i2v-2.2-quant-dummy-inputs

Conversation

@ThomasNing

Copy link
Copy Markdown

Problem

get_dummy_wan_inputs (called by WanPipeline.quantize_transformerqwix.quantize_model) assumes a single pipeline.transformer and the single-transformer prepare_latents() signature. The two-expert WanPipelineI2V_2_2 (Wan2.2-I2V-A14B) has low_noise_transformer / high_noise_transformer (no .transformer) and a different prepare_latents() signature, so use_qwix_quantization=True crashes:

AttributeError: 'WanPipelineI2V_2_2' object has no attribute 'transformer'

and, once that's worked around:

TypeError: WanPipelineI2V_2_2.prepare_latents() got an unexpected keyword argument 'vae_scale_factor_temporal'

Fix

When pipeline.transformer is absent (two-expert pipeline), build the dummy latents directly in the (B, C, F, H, W) layout WanModel.__call__ expects, taking num_channels_latents from an existing expert (low_noise_transformer). The single-transformer path is unchanged.

Validation

On Wan2.2-I2V-A14B (TPU v6e-16, 1080p, 4-step): with this change, quantization proceeds past both errors above into qwix.quantize_model (the model forward traces correctly with (latents, timesteps, prompt_embeds)). A separate qwix↔JAX version issue (conv_general_dilated() got an unexpected keyword argument 'out_sharding') then surfaces in our environment — unrelated to this change.

get_dummy_wan_inputs (used by WanPipeline.quantize_transformer) assumed a single
pipeline.transformer and the single-transformer prepare_latents() signature.
WanPipelineI2V_2_2 (Wan2.2-I2V-A14B) is two-expert: it has
low_noise_transformer / high_noise_transformer (no .transformer) and a different
prepare_latents() signature, so qwix quantization crashed with
AttributeError: 'WanPipelineI2V_2_2' object has no attribute 'transformer'
and then
TypeError: prepare_latents() got an unexpected keyword argument 'vae_scale_factor_temporal'.

When pipeline.transformer is absent, build dummy latents directly in the
(B, C, F, H, W) layout WanModel.__call__ expects, taking num_channels_latents
from an existing expert. The single-transformer path is unchanged.

Validated on Wan2.2-I2V-A14B (v6e): quantization now proceeds past these errors
into qwix.quantize_model.
@ThomasNing ThomasNing requested a review from entrpn as a code owner June 24, 2026 01:00
@google-cla

google-cla Bot commented Jun 24, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Comment thread src/maxdiffusion/maxdiffusion_utils.py Outdated
Comment on lines +361 to +371
if getattr(pipeline, "transformer", None) is not None:
latents = pipeline.prepare_latents(
batch_size,
vae_scale_factor_temporal=pipeline.vae_scale_factor_temporal,
vae_scale_factor_spatial=pipeline.vae_scale_factor_spatial,
height=config.height,
width=config.width,
num_frames=config.num_frames,
num_channels_latents=pipeline.transformer.config.in_channels,
)
else:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Wondering instead of an if/else block, can we make this cleaner and more robust by completely decoupling the dummy generation from the pipeline methods and generate the inputs uniformly for all pipeline variants?

@Perseus14 Perseus14 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. I have added a comment, PTAL!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants